package zdream.pmfield.stage.message;

import java.util.Objects;

import zdream.pmfield.data.foe.Foe;
import zdream.pmfield.stage.object.FoeActor;
import zdream.pmfield.stage.object.Seat;

/**
 * @author Zdream
 * @date 2023-11-15
 * @since 0.0.1
 */
public class FoeLeaveMessage extends StageMessage {
	public final Foe foe;
	public final Seat seat;
	public final DepartureReason reason;

	public FoeLeaveMessage(Foe foe, Seat seat, DepartureReason reason) {
		this.type = StageMessageType.REPORT;
		this.foe = Objects.requireNonNull(foe);
		this.seat = Objects.requireNonNull(seat);
		this.reason = Objects.requireNonNull(reason);
	}

	public static FoeLeaveMessage fromFaint(FoeActor foe) {
		return new FoeLeaveMessage(foe.foe, foe.seat, DepartureReason.FAINT);
	}

	public static FoeLeaveMessage fromMovement(FoeActor foe) {
		return new FoeLeaveMessage(foe.foe, foe.seat, DepartureReason.MOVEMENT);
	}

	public static enum DepartureReason {
		FAINT,
		MOVEMENT,
		SWITCH,
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder(100);
		builder.append("[FL]").append(' ');
		foe.appendStringWithoutHp(builder);
		builder.append(' ').append("因为");

		switch (reason) {
		case FAINT: builder.append("被击败"); break;
		case MOVEMENT: builder.append("移动"); break;
		case SWITCH: builder.append("交换"); break;
		}

		builder.append("离开了位置").append(' ');
		seat.appendStringWithoutFoe(builder);
		return builder.toString();
	}
}
